package com.cyandpos.pad.login.configs;

import android.text.TextUtils;


import com.cyandpos.pad.common.commondata.ErpCommonData;
import com.cyandpos.pad.common.commondata.SktConfigConstant;
import com.cyandpos.pad.common.commondata.SktConfigIdPrintTypeConstant;
import com.cyandpos.pad.posdata.ConfigInfo;
import com.cyandpos.pad.utils.CommonUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/4/7.
 * 款台配置信息
 */

public class GetConfigs {
    public static final int KEY_GOOD_CODE_LENGTH = 1101002002;//商品代码长度
    public static final int KEY_SALEPERSON_CODE_LENGTH = 12;//营业员代码长度补零
    public static final int KEY_TRACE_IS_REALTIME_DEDUCTION_MONEY = 950000009;//是否为立减扣款
    public static final int KEY_CARD_COUPON_IS_RECORD_SALES = 1101000007;//优惠券金额是否记销售


//    public static final int KEY_TICKET_PRINTER_NUM = 1500000002;//销售小票打印份数
//    public static final int KEY_BAR_VERSION_ROUNDING_METHOD = 1500001005;//条码版舍零方式

    private static List<ConfigInfo> config = new ArrayList<ConfigInfo>();
    public static List<ConfigInfo> getConfigInfos() {
        if (config.isEmpty()) {
            config.add(new ConfigInfo(KEY_GOOD_CODE_LENGTH, ""));//设定商品店内流水码的长度
            config.add(new ConfigInfo(KEY_TRACE_IS_REALTIME_DEDUCTION_MONEY, "2"));//是否为立减扣款  2非立即扣款//            position 0
            config.add(new ConfigInfo(KEY_CARD_COUPON_IS_RECORD_SALES, ""));//优惠券金额是否记销售  0:不记销售 1:记销售     position 1
            config.add(new ConfigInfo(KEY_SALEPERSON_CODE_LENGTH, ""));//营业员补零
        }
        return config;
    }


    /***
     * 获取商品代码长度
     *
     * @return int
     */
    public static int getGoodsCodeLength() {//设定商品店内流水码的长度
        int length = 0;
        for(ConfigInfo item :config){
            if(item.getId() == KEY_GOOD_CODE_LENGTH){
                String value = item.getValue();
                if (!TextUtils.isEmpty(value)) {
                    length =Integer.parseInt(value);
                }
                break;
            }
        }
        return length;
    }

    /**
     * 优惠券金额是否记销售  0:不记销售 1:记销售
     *
     * @return string
     */
    public static int getCouponWriteSale() {
        int way = 0;
        for(ConfigInfo item :config){
            if(item.getId() == KEY_CARD_COUPON_IS_RECORD_SALES){
                String value = item.getValue();
                if (!TextUtils.isEmpty(value)) {
                    way =Integer.parseInt(value);
                }
                break;
            }
        }
        return way;
    }
    /***
     * 营业员代码长度
     * @return int
     */
    public static int getPersonCodeLength() {
        int length = 0;
        for(ConfigInfo item :config){
            if(item.getId() == KEY_SALEPERSON_CODE_LENGTH){
                String code = item.getValue();
                if (!TextUtils.isEmpty(code)) {
                    length = Integer.parseInt(code);
                }
                break;
            }
        }
        return length;
    }

    /**
     * 储值卡优惠券是否立即扣款
     * @return true 立即扣款
     */
    public static boolean isTradeCutPayment() {
        boolean isCutpay = false;
        for(ConfigInfo item :config){
            if(item.getId() == KEY_TRACE_IS_REALTIME_DEDUCTION_MONEY){
                String code = item.getValue();
                if(!code.equals("2"))//2 结账时扣款
                    isCutpay = true;
                break;
            }
        }
        return isCutpay;
    }

    public static int ticketPrintCount() {
        int printNum = 1;
        for (int i = 0; i< ErpCommonData.loadConfig.getSkt().getSktconfigList().size(); i++){
            if (ErpCommonData.loadConfig.getSkt().getSktconfigList().get(i).getLx()
                    .equals(SktConfigConstant.SKT_CONFIG_TYPE_PRINTING)) { //类型=4 打印相关
                String id = ErpCommonData.loadConfig.getSkt().getSktconfigList().get(i).getId();
                if(id.equals(SktConfigIdPrintTypeConstant.SKT_CONFIG_PRINT_NUM_TERMINAL)){
                    if(CommonUtils.isNullOrEmpty(ErpCommonData.loadConfig.getSkt().getSktconfigList().get(i).getValue()))
                        printNum = 1;
                    else
                        printNum =Integer.parseInt(ErpCommonData.loadConfig.getSkt().getSktconfigList().get(i).getValue());
                    break;
                }

            }
        }
        return printNum;
    }
}
